package com.hebust.mapper;

import com.hebust.utils.teacher.MyScore;
import com.hebust.utils.teacher.StudentScore;
import com.hebust.utils.teacher.Teach;
import com.hebust.utils.teacher.TeacherSchedule;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

@Mapper
public interface TeacherMapper {

    // 教师评分查询

    @Select("select score_stu as score,\n" +
            "score_count as count\n" +
            "from teachers\n" +
            "where t_id = #{tid}")
    List<MyScore> my_score(@Param("tid") int tid);

    // 修改密码
    @Update("update teachers\n" +
            "set t_password = #{password}\n" +
            "where t_id = #{tid}")
    Integer update_teacherpassword(int tid, String password);

    // 成绩录入
    @Select("SELECT\n" +
            "sc_id as id,\n" +
            "co_name as cname,\n" +
            "s_name as sname,\n" +
            "sc_score as score\n" +
            "from studentscore,course,students\n" +
            "where sc_teacher_id = 1\n" +
            "and sc_student_id = s_id\n" +
            "and sc_course_id = co_id\n" +
            "and co_name like concat('%',#{cname},'%')\n" +
            "and s_name like concat('%',#{sname},'%')")
    List<StudentScore> show_studentscore(@Param("tid") int tid, @Param("cname") String cname, @Param("sname") String sname);

    // 教师打分
    @Update("update studentscore\n" +
            "set sc_score = #{score}\n" +
            "where sc_id = #{id}")
    Integer add_studentscore(@Param("id") int id, @Param("score") int score);

    // 授课查询
    @Select("SELECT \n" +
            "co_id as id,\n" +
            "co_name as cname,\n" +
            "co_grade as grade,\n" +
            "co_credit as credit,\n" +
            "co_time as ttime,\n" +
            "co_location as location,\n" +
            "co_select_count as sselect,\n" +
            "co_exam_date as etime,\n" +
            "co_exam_location as elocation\n" +
            "from course,teachers\n" +
            "where t_id = #{tid}\n" +
            "and t_id = co_teacher_id")
    List<Teach> show_teachercourse(@Param("tid") int tid);

    // 编辑上课时间和地点
    @Update("update course\n" +
            "set co_exam_date = #{etime},\n" +
            "co_exam_location = #{elocation}\n" +
            "where co_id = #{id}")
    Integer edit_courseinformation(@Param("id") int id, @Param("etime") String etime, @Param("elocation") String elocation);

    // 课表
    @Select("SELECT\n" +
            "co_name as cname,\n" +
            "co_time as ctime,\n" +
            "co_location as location\n" +
            "from course\n" +
            "WHERE co_teacher_id = #{tid}")
    List<TeacherSchedule> show_teachercourseschedule(@Param("tid") int tid);
}
